package com.shujia

object Code47Generic {
  def main(args: Array[String]): Unit = {
    /**
     * 泛型：
     * Scala里面标记泛型使用的是 []
     *
     */

    val a1 = new A[String]
    a1.fun("String")
    val a2 = new A[Int]
    a2.fun(10)

    //    val father = new Father()
    val value: B[Father] = new B[Son]() // +T
    val value1: C[Son] = new C[Father]() // -T

    val value2 = new Message[Son]
    value2.fun1(new Message[Father])

    val value3 = new Message[Father]
    value3.fun2(new Message[Son])



  }
}

class A[T] {
  def fun(t: T): Unit = {
    println("fun函数执行了,获取到参数：" + t)
  }
}

class B[+T] {

  //  def fun(t: T): Unit = {
  //
  //  }
}

class C[-T] {

  //  def fun(t: T): Unit = {
  //
  //  }
}

class Message[A] {
  // 以A作为其下边界
  def fun1(message: Message[_ >: A]): Unit = {
    println("fun函数可以执行....")
  }

  // 表示以A作为其上边界
  def fun2(message: Message[_ <: A]): Unit = {
    println("fun函数可以执行....")
  }
}


class Father {

}

class Son extends Father {

}


